package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 新增员工
     * @param employee
     * @return
     */
    @Insert("insert into employee(username, name, password, phone, sex, id_number, status, create_time, create_user, update_time, update_user) " +
            "values" +
            "(#{username}, #{name}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser})")
    @AutoFill(OperationType.INSERT)
    void insertEmployee(Employee employee);


    /**
     * 员工分页查询
     * @param employeePageQueryDTO
     * @return
     */
    List<Employee> queryByPage(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 启用/禁用员工
     * @param employee
     */
    //使用trim标签忽略sql语句中尾部逗号
    @AutoFill(OperationType.UPDATE)
    void update(Employee employee);

    /**
     * 根据员工id返回信息
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    EmployeeDTO getById(Long id);
}
